<?php

/**
 * @file input_opt.php
 * @brief Clase para las opciones de los campos en un formulario
 * @author DyrTechnologies
 * @version V 1.0
 * @date Wed Oct 03 2007
 *
 *  Part of the CEFIRO dynamic web framework project
 *
 *  Copyright (C) 2007  Dyr technologies http://dyrtech.com.ve
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

@define("UNASSIGNED","");

/**
 * @class Clase input_opt
 */

class input_opt{
	private $onClic;
	private $onBlur;
	private $onFocus;
	private $onKeyPress;
	private $onKeyUp;
	private $onKeyDown;
	private $onSubmit;
	private $onChange;
	private $onMouseOver;
	private $extra;
	private $style;

	/**
	* Ajusta el atributo indicado de la clase a vacio
	*
	* @return vacio/no asignado
	*/
	private function opt_reset(){
		return UNASSIGNED;
	}

	/**
	 * @brief Constructor de la clase, por omision se ajustan a vacio todos los atributos del campo
	 *
	 * @return input_opt Instancia de la Clase input_opt
	 */
	public function input_opt(){

		/**
		 * @brief Al iniciar la instancia reiniciamos todos sus valores
		 */
		$this->onClic=$this->opt_reset();
		$this->onBlur=$this->opt_reset();
		$this->onFocus=$this->opt_reset();
		$this->onKeyPress=$this->opt_reset();
		$this->onKeyUp=$this->opt_reset();
		$this->onKeyDown=$this->opt_reset();
		$this->onSubmit=$this->opt_reset();
		$this->onChange=$this->opt_reset();
		$this->onMouseOver=$this->opt_reset();
		$this->extra=$this->opt_reset();
	}

	/**
	 * @brief Por cada atributo (opcion) nueva debe agregarse una opcion set y una opcion get
	 *
	 * @param string $val Valor a asignar a la opcion deseada, notese que es una cadena
	 */

	/**
	 * Pares de Funciones (set,get) para la Opcion onClic del campo
	 *
	 */
	public function set_onClic($val){
		$this->onClic=$val;
	}
	public function get_onClic(){return $this->onClic;}

	/**
	* Pares de Funciones (set,get) para la Opcion onClic del campo
	*
	*/
	public function set_onBlur($val){
		$this->onBlur=$val;
	}
	public function get_onBlur(){return $this->onBlur;}

	/**
	* Pares de Funciones (set,get) para la Opcion onClic del campo
	*
	*/
	public function set_onFocus($val){
		$this->onFocus=$val;
	}
	public function get_onFocus(){return $this->onFocus;}

	/**
	 * Pares de Funciones (set,get) para la Opcion onKeyPress del campo
	 *
	 */
	public function set_onKeyPress($val){
		$this->onKeyPress=$val;
	}
	public function get_onKeyPress(){return $this->onKeyPress;}

	/**
	 * Pares de Funciones (set,get) para la Opcion onKeyUp del campo
	 *
	 */
	public function set_onKeyUp($val){
		$this->onKeyUp=$val;
	}
	public function get_onKeyUp(){return $this->onKeyUp;}

	/**
	 * Pares de Funciones (set,get) para la Opcion onKeyDown del campo
	 *
	 */
	public function set_onKeyDown($val){
		$this->onKeyDown=$val;
	}
	public function get_onKeyDown(){return $this->onKeyDown;}

	/**
	* Pares de Funciones (set,get) para la Opcion onMouseOver del campo
	*
	*/
	public function set_onMouseOver($val){
		$this->onMouseOver=$val;
	}
	public function get_onMouseOver(){return $this->onMouseOver;}
	
	/**
	* Pares de Funciones (set,get) para la Opcion onSubmit del campo
	*
	*/
	public function set_onSubmit($val){
		$this->onSubmit=$val;
	}
	public function get_onSubmit(){return $this->onSubmit;}

	/**
	* Pares de Funciones (set,get) para el estilo
	*
	*/
	public function set_style($_style){
		if($_style){
			$this->style="input-lbl";
			}
	}

	public function get_style(){
		return $this->style;
	}


	/**
	* Pares de Funciones (set,get) para la Opcion onChange del campo
	*
	*/
	public function set_onChange($val){
		$this->onChange=$val;
	}
	public function get_onChange(){return $this->onChange;}

	/**
	 * Pares de Funciones (set,get) para las opciones extras del campo
	 *
	 */
	public function set_extra($val){
		$this->extra=$val;
	}
	public function get_extra(){
		return $this->extra;
	}

	/**
	 * @brief Iguala la instancia que la llama a la variable que se le pasa en el parametro
	 * @brief NOTAR que el parametro debe ser de tipo input_opt
	 *
	 * @param input_opt $that
	 */
	public function equalize(input_opt $that){
		$this->onBlur=$that->onBlur;
		$this->onClic=$that->onClic;
		$this->onFocus=$that->onFocus;
		$this->onKeyPress=$that->onKeyPress;
		$this->onKeyUp=$that->onKeyUp;
		$this->onKeyDown=$that->onKeyDown;
		$this->onSubmit=$that->onSubmit;
		$this->onChange=$that->onChange;
		$this->onMouseOver=$that->onMouseOver;
		$this->extra=$that->extra;
	}

	/**
	 * @brief Devuelve la instancia como una cadena
	 *
	 * @return string $retval
	 */
	public function get_input_opt(){
		$retval="";
		if($this->onBlur)
			$retval.="onBlur=\"".$this->onBlur."\""." ";
		if($this->onClic)
			$retval.="onClick=\"".$this->onClic."\""." ";
		if($this->onFocus)
			$retval.="onFocus=\"".$this->onFocus."\""." ";
		if($this->onKeyPress)
			$retval.="onKeyPress=\"".$this->onKeyPress."\""." ";
		if($this->onKeyUp)
			$retval.="onKeyUp=\"".$this->onKeyUp."\""." ";
		if($this->onKeyDown)
			$retval.="onKeyDown=\"".$this->onKeyDown."\""." ";
		if($this->onMouseOver)
			$retval.="onMouseOver=\"".$this->onMouseOver."\""." ";
		if($this->onSubmit)
			$retval.="onSubmit=\"".$this->onSubmit."\""." ";

		if($this->style)
			$retval.="class=\"".$this->style."\""." "."readonly="."\""."true"."\""." ";
		if($this->onChange)
			$retval.="onChange=\"".$this->onChange."\""." ";
		if($this->extra)
			$retval.=$this->extra." ";
		return $retval;
	}
}